package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.Material;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.util.Map;

@EqualsAndHashCode(callSuper = false)
@Data
public class MaterialVo extends BaseVo {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "状态")
    private Integer state ;

    @ApiModelProperty(value = "类型")
    private Integer type;
    private String typeStr;

    @ApiModelProperty(value = "商品描述")
    private String description;

    @ApiModelProperty(value = "商品信息")
    private CommodityVo commodity;

    private MaterialVo() {
    }

    public static MaterialVo create(Material material){
        MaterialVo materialVo = new MaterialVo();
        BeanUtils.copyProperties(material,materialVo,"commodity");
        materialVo.translationValueStr();
        if(material.getCommodity()!=null){
            materialVo.commodity = CommodityVo.create(material.getCommodity());
        }
        return materialVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        this.typeStr = map.get(WZCL.GROUP_NAME.MATERIAL_TYPE).get(this.type);
    }

    @Override
    public void processResources() {

    }
}
